package org.puremvc.as3.multicore.utilities.unifiedloader.clients.flash
{
/*
 	PureMVC UnifiedLoader Utility
 	Copyright (c) 2008 neil manuell
  	Your reuse is governed by the Creative Commons Attribution 3.0 License
 */
	import flash.events.*;
	import flash.net.URLLoader;
	
	import org.puremvc.as3.multicore.utilities.unifiedloader.clients.LoaderClientBase;
	import org.puremvc.as3.multicore.utilities.unifiedloader.interfaces.ILoaderClientInfo;

	

	
	public class URLLoaderClient extends LoaderClientBase
	{
		public static const NAME:String = "URLLoaderClient";
		
		private var mLoader:URLLoader;
		
		public function URLLoaderClient(cli:ILoaderClientInfo)
		{
			super(cli)
		}
		

		
		override protected function initialiseLoad():void
		{
			mLoader = new URLLoader();
		}
		
		
		override protected function startLoad():void
		{
			mLoader.load(loaderClientInfo.urlRequest);
		}
		
		
		override protected function prepareAsset(event:Event):void{
			
			var	data:String;			
			
			data = String(mLoader.data);
			loaderClientInfo.setAsset( data );
			
			
		}
		
		
		override protected function addListeners():void
		{
			mLoader.addEventListener(Event.COMPLETE, loadCompleteHandler);
				mLoader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
				mLoader.addEventListener(ProgressEvent.PROGRESS, relayHandler);
				mLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, relayHandler);
				mLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, relayHandler);
		}

		
		override protected function removeListeners():void{
			
				mLoader.removeEventListener(Event.COMPLETE, loadCompleteHandler);
				mLoader.removeEventListener(IOErrorEvent.IO_ERROR, errorHandler);
				mLoader.removeEventListener(ProgressEvent.PROGRESS, relayHandler);
				mLoader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, relayHandler);
				mLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, relayHandler);
				
				
			
		}
		
	}
}

